
package com.ifcar.app.fragment;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

public class FragmentUtil {
    public static void executePendingTransactions(FragmentManager fm) {
        fm.executePendingTransactions();
    }

    public static void commit(FragmentManager fm, FragmentTransaction ft, boolean checkStateLoss) {
        commitAndExecInternal(fm, ft, checkStateLoss, false);
    }

    public static void commitAndExec(FragmentManager fm, FragmentTransaction ft,
            boolean checkStateLoss) {
        commitAndExecInternal(fm, ft, checkStateLoss, true);
    }

    private static void commitAndExecInternal(FragmentManager fm, FragmentTransaction ft,
            boolean checkStateLoss, boolean exec) {
        if (checkStateLoss) {
            ft.commit();
        } else {
            ft.commitAllowingStateLoss();
        }

        if (exec) {
            fm.executePendingTransactions();
        }
    }
}
